/*
 * Copyright 2004 original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jbfilter.hibernate;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.jbfilter.bean.FilterComponentBean;
import org.jbfilter.core.Filter;
import org.jbfilter.hibernate.exception.DataAccessException;

/**
 * The filter contract for data tier filtering using the Hibernate ORM framework.
 * Mixing database/Java filtering is supported. That means that the {@link #addFilterComponent(org.jbfilter.core.FilterComponent)}
 * method supports {@link FilterComponentBean} (JVM side filtering) and {@link FilterComponentHibernate}
 * (data tier side filtering) subclasses.
 * @author Marcus Adrian
 * @param <E> for type safety the filter must be parameterized with the type of the beans to filter.
 */
public interface FilterHibernate<E> extends Filter<E> {
	/**
	 * Doesn't need any {@link SessionFactory} set because a {@link Session} is passed in.
	 * Note that for the apparently useless {@link Class} parameter there is no workaround because of the nature
	 * of java language generics (type erasure).
	 * @param clazz pass in the class of the generic type parameter E, no other class works
	 * @param session
	 * @return the filtered list
	 * @throws DataAccessException
	 */
	List<E> filter(Class<E> clazz, Session session) throws DataAccessException;
	/**
	 * Uses the factory set by {@link #setSessionFactory(SessionFactory)}.
	 * Note that for the apparently useless {@link Class} parameter there is no workaround because of the nature
	 * of java language generics (type erasure).
	 * @param clazz pass in the class of the generic type parameter E, no other class works
	 * @return the filtered list
	 * @throws DataAccessException
	 */
	List<E> filter(final Class<E> clazz) throws DataAccessException;
	@Override
	FilterHandlerHibernate<E> newFilterHandler();
	/**
	 * Must be set if using method {@link #filter(Class)}.
	 * @param sessionFactory
	 */
	void setSessionFactory(SessionFactory sessionFactory);
}
